<script type="text/javascript">

$(document).ready(function(){
							$('.check').live('click',function(){
								value= $(this).val().split('_');
								doanp_th =$("#thang"+value[0]).val();
								tong_thang = $('#dathu'+value[0]).val();
								tong = $('#tong').val();
								
								if ($(this).prop('checked')==true)
								{
									tong_thang = parseInt(tong_thang,10)  +parseInt(doanp_th,10);
									tong = parseInt(tong,10) + parseInt(doanp_th,10);
								}
								else
								{
									tong_thang = parseInt(tong_thang,10) - parseInt(doanp_th,10);;
									tong = parseInt(tong,10) - parseInt(doanp_th,10);;
								}
								
								$('#dathu'+value[0]).val(tong_thang);
								$('#tong').val(tong);
								$("td#tong"+value[0]).html(numberformat(tong_thang));
								$("td#tongtd").html(numberformat(tong));
								
								});
							
							$('.checkall').live('click',function(){
								doanviennum =$('#doanvien').val();
								thang = $(this).prop('id');
								doanp_th =$("#thang"+thang).val();
								if ($(this).prop('checked')==true)
								{
									ch =true;
									tong_thang = parseInt(doanp_th,10) * parseInt(doanviennum,10);
								}
								else
								{
									tong_thang=$('#dt'+thang).val();;
									ch =false;
								}
								for(i=0;i<doanviennum;i++)
								{
									$('#check'+thang+'_'+i).prop('checked',ch);
								}
								tong_th_trc = $('#dathu'+thang).val();
								tong_trc = $('#tong').val();
								tong =  parseInt(tong_trc,10) + (tong_thang- parseInt(tong_th_trc,10));
								$('#dathu'+thang).val(tong_thang);
								$("td#tong"+thang).html(numberformat(tong_thang));
								
								$('#tong').val(tong);
								$("td#tongtd").html(numberformat(tong));
								});
});
</script>
<div class="tgdongdoanphisvs index">
<h2 style="text-align: center">Quản lý đoàn phí</h2>
<div align="center" style="margin-top: 2px;">
<strong><?php 

    echo 'Chi đoàn: '.$chidoansv['Chidoansv'] ['tenchidoan'].' ('.$chidoansv['Khoa'] ['tenkhoa'].')<br>';
?></strong>
</div>
<?php if(empty($thangs)){?>
	<h2>Năm Học Chưa Được Tạo</h2>
	<?php }elseif(empty($sinhviens)){?>
		<h2>Chi Đoàn Chưa Có Đoàn Viên Nào</h2>
	<?php }else{
		echo $this->Form->create('Tgdongdoanphisv',array('type'=>'post','url'=>array('controller'=>'tgdongdoanphisvs','action'=>'doanp',$chidoan,$namhoc)));
		echo $form->input('namhoc_id',array('id'=>'namhoc_id','label'=>'Năm học','type'=>'select','options'=>$namhocs,'selected'=>$namhoc));
		?>
		<div id='div_update'>
		<div align="center" style="margin-top: 2px;">
		<strong>
		<?php echo 'Năm học: '.$nhoc[$namhoc];?>
		</strong>
		</div>    
		<?php 
			echo $html->link('Xuất Excel',array('action'=>'xuatexcel',$chidoan,$namhoc));
	    	$url = array('controller'=>'tgdongdoanphisvs','action'=>'xoaddong','params'=>$chidoan."_".$namhoc);
	    	echo $this->ctable->doanph('Tgdongdoanphisv',$thangs,$sinhviens,$dulieu,$dathu,$doanphi,$url,$users);
		?>
		</div>
<div align="center" style="margin-top: 2px;">
 <?php
	   echo $this->Form->end(__('Lưu', true));
	}
?>
</div>
<?php
$this->Js->get('#namhoc_id')->event('change',
							$this->Js->request(array('controller' => 'tgdongdoanphisvs', 'action' => 'updatedoanp',$chidoan),
							array('update' => '#div_update','async' => true,
							'dataExpression' => true,'method' => 'post',
							'data' => $js->serializeForm(array('isForm' => false, 'inline' => true))))); 
?>
</div>